package com.ledijiaoyu.autogate.packet.response;

import cn.dinkevin.xui.util.StringUtil;

/**
 * Create with Android Studio
 * Author: chengpengfei
 * Date: 2018/6/2
 * Time: 2:20 PM
 * Description:读取内存信息回复
 */
public class ReadCardInfoResponse extends AutoGateResponse{

    private String mCardNumber;

    @Override
    public boolean decode(byte[] buffer) {
        boolean parentDecode = super.decode(buffer);
        boolean childDecode = false;
        if(parentDecode){
            // 数据包 H001 G4528 K 001 1 0 140317003331 3029168724 4A
            // K:无意义
            // 001：机号
            // 1：读卡器编号
            // 0：是否开启继电器
            // 140317003331：年月日时分秒
            // 3029168724：卡号（长度为10位）
            mPoint = 9 + 1 + 3 + 2 + 12;
            char[] t_buffer = new char[]{mBuffer.get(mPoint++),
                            mBuffer.get(mPoint++),
                            mBuffer.get(mPoint++),
                            mBuffer.get(mPoint++),
                            mBuffer.get(mPoint++),
                            mBuffer.get(mPoint++),
                            mBuffer.get(mPoint++),
                            mBuffer.get(mPoint++),
                            mBuffer.get(mPoint++),
                            mBuffer.get(mPoint++)};
            mCardNumber = StringUtil.char2String(t_buffer);
        }
        return parentDecode && childDecode;
    }

    public String getCardNumber(){
        return mCardNumber;
    }
}
